package com.myzl.web.controller.coal;

import com.myzl.coal.domain.ThresholdData;
import com.myzl.coal.service.IThresholdDataService;
import com.myzl.common.annotation.Log;
import com.myzl.common.core.controller.BaseController;
import com.myzl.common.core.domain.AjaxResult;
import com.myzl.common.core.page.TableDataInfo;
import com.myzl.common.enums.BusinessType;
import com.myzl.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 阈值Controller
 *
 * @author myzl
 * @date 2022-11-28
 */
@RestController
@RequestMapping("/coal/thresholdData")
public class ThresholdDataController extends BaseController
{
    @Autowired
    private IThresholdDataService thresholdDataService;

    /**
     * 查询阈值列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ThresholdData thresholdData)
    {
        startPage();
        List<ThresholdData> list = thresholdDataService.selectThresholdDataList(thresholdData);
        return getDataTable(list);
    }

    /**
     * 导出阈值列表
     */
    @PreAuthorize("@ss.hasPermi('coal:thresholdData:export')")
    @Log(title = "阈值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ThresholdData thresholdData)
    {
        List<ThresholdData> list = thresholdDataService.selectThresholdDataList(thresholdData);
        ExcelUtil<ThresholdData> util = new ExcelUtil<ThresholdData>(ThresholdData.class);
        util.exportExcel(response, list, "阈值数据");
    }

    /**
     * 获取阈值详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(thresholdDataService.selectThresholdDataById(id));
    }

    /**
     * 新增阈值
     */
    @Log(title = "阈值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ThresholdData thresholdData)
    {
        return toAjax(thresholdDataService.insertThresholdData(thresholdData));
    }

    /**
     * 修改阈值
     */
    @Log(title = "阈值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ThresholdData thresholdData)
    {
        return toAjax(thresholdDataService.updateThresholdData(thresholdData));
    }

    /**
     * 删除阈值
     */
    @Log(title = "阈值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(thresholdDataService.deleteThresholdDataByIds(ids));
    }

    @GetMapping("/getDeviceAgreement/{deviceTypes}")
    public AjaxResult getDeviceAgreement(@PathVariable List<String> deviceTypes){
        return thresholdDataService.selectDeviceAgreement(deviceTypes);
    }
}
